package com.example.demo.spring;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * 最基本的 JAVA反射
 */
public class BaseReflex {

    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        // 获取class 类
        Class<?> aClass = Class.forName("com.example.demo.spring.Person");
        Class<Person> personClass = Person.class;

        // 反射创建对象
        Constructor<?> constructor = aClass.getConstructor();
        Object o = constructor.newInstance();
        Person person = (Person) o;
        person.run();
    }

}

class Person{
    private String name;

    public void run(){
        System.out.println("运动员跑步");
    }
}
